//
//  MCSendHBDetailHeaderView.m
//  XDYL
//
//  Created by MC on 2018/3/20.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCSendHBDetailHeaderView.h"


@interface MCSendHBDetailHeaderView()

@property (nonatomic ,strong)UIImageView * logoImgV;
@property (nonatomic ,strong)UILabel * lab1 ;//张学友
@property (nonatomic ,strong)UILabel * lab2 ;//恭喜发财，大吉大利！（红包名称）
@property (nonatomic ,strong)UILabel * lab3 ;//共十个红包，已抢10/10。

@end

@implementation MCSendHBDetailHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    self.backgroundColor=[UIColor whiteColor];
    
    _logoImgV=[[UIImageView alloc]init];
    _logoImgV.image = [UIImage imageNamed:@"fachu"];
    [self addSubview:_logoImgV];
    [_logoImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(self.mas_top).offset(25);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
    
    /*
     * name
     */
    _lab1=[[UILabel alloc]init];
    _lab1.text=@"加载中...";
    _lab1.font=[UIFont systemFontOfSize:12];
    _lab1.textColor=RGB(34,34,34);
    _lab1.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_lab1];
    [_lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(_logoImgV.mas_bottom).offset(0);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(26);
    }];
    
    /*
     * 恭喜发财，大吉大利！（红包名称）
     */
    
    _lab2=[[UILabel alloc]init];
    _lab2.text=@"加载中...";
    _lab2.font=[UIFont systemFontOfSize:12];
    _lab2.textColor=RGB(161,161,161);
    _lab2.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_lab2];
    [_lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(_logoImgV.mas_bottom).offset(19);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(42);
    }];
    

    
    _lab3=[[UILabel alloc]init];
    _lab3.text=@"加载中...";
    _lab3.font=[UIFont systemFontOfSize:9];
    _lab3.textColor=RGB(161,161,161);
    _lab3.textAlignment=NSTextAlignmentLeft;
    [self addSubview:_lab3];
    [_lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(23);
        make.bottom.equalTo(self.mas_bottom).offset(-6);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(15);
    }];
    
    /*
     * 下划线
     */
    UIView * line =[[UIView alloc]init];
    line.backgroundColor=RGB(213,213,213);
    [self  addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-23);
        make.left.equalTo(self.mas_left).offset(23);
        make.bottom.equalTo(self.mas_bottom).offset(-1);
        make.height.mas_equalTo(0.5);
        
    }];
    
    
    
}


+(CGFloat)computeHeight:(id)info{
    return 229;
}


-(void)setDataSource:(MCDetailTotalModel *)dataSource{
    _dataSource = dataSource;

    _lab1.text=[NSString stringWithFormat:@"%@",dataSource.UserName];
    _lab2.text=[NSString stringWithFormat:@"%@",dataSource.Name];
    _lab3.text=[self getTip:dataSource];

    
    if (dataSource.HeadPortrait.length<1) {
        _logoImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"MoRenPerson_1"]];
    }else{
        _logoImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"MoRenPerson_%@",dataSource.HeadPortrait]];
    }
}

-(NSString *)getTip:(MCDetailTotalModel *)dataSource{
    
    NSString * tip = @"";
    NSString * PersonConsumption=[NSString stringWithFormat:@"%@",dataSource.PersonConsumption];
    
    NSString * PersonRechargeMoney=[NSString stringWithFormat:@"%@",dataSource.PersonRechargeMoney];
    
    if (PersonConsumption.length>0) {
        PersonConsumption=GetTwoDigitRealSNum(PersonConsumption);
    }
    if (PersonRechargeMoney.length>0) {
        PersonRechargeMoney=GetTwoDigitRealSNum(PersonRechargeMoney);
    }
    
    if (([PersonRechargeMoney integerValue]>0)&&([PersonConsumption integerValue]>0)) {
        tip=[NSString stringWithFormat:@"消费≥%@元并充值≥%@元才可领取",PersonConsumption,PersonRechargeMoney];
        
    }else if ([PersonConsumption integerValue]>0){
        tip=[NSString stringWithFormat:@"消费≥%@元才可领取",PersonConsumption];
    }else if ([PersonRechargeMoney integerValue]>0){
        tip=[NSString stringWithFormat:@"充值≥%@元才可领取",PersonRechargeMoney];
    }
    
    if (tip.length>0) {
        tip=[NSString stringWithFormat:@"共%@个红包%@元，已抢%@/%@(%@)",dataSource.Qty,dataSource.Amount,dataSource.ReceivedNum,dataSource.Qty,tip];
    }else{
        tip=[NSString stringWithFormat:@"共%@个红包%@元，已抢%@/%@",dataSource.Qty,dataSource.Amount,dataSource.ReceivedNum,dataSource.Qty];
    }
    return tip;
}
@end















































